//
//  AttributScroView.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/3/1.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "AttributScroView.h"
#import "AttributeView.h"

@interface AttributScroView ()
@property(nonatomic,strong)NSMutableArray * indexArray;
@property(nonatomic,strong)void(^complect)(NSArray * indexs);
@end

@implementation AttributScroView

- (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *)titles attributeTextArrays:(NSArray *)textArrayss complect:(void(^)(NSArray * indexs))complect{
    self= [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _complect = complect;
        _indexArray = [NSMutableArray array];
        CGFloat Y=0;
        NSMutableDictionary * indexDic = [NSMutableDictionary dictionary];
        for (int i = 0; i<titles.count; i++) {
            AttributeView * attrView = [[AttributeView alloc]initWithFrame:flexibleFrame(CGRectMake(0, Y, frame.size.width, 100), YES) title:titles[i] attributeTexts:textArrayss[i] complect:^(NSInteger index) {
                [_indexArray addObject:@(index)];
                [indexDic setObject:[NSString stringWithFormat:@"%ld",index] forKey:[NSString stringWithFormat:@"%d",i]];
                [_indexArray removeAllObjects];
                for (int i = 0; i< indexDic.allKeys.count; i++) {
                    NSInteger index = [indexDic[[NSString stringWithFormat:@"%d",i]]integerValue];
                    [_indexArray addObject:@(index)];
                }
                if (_indexArray.count == titles.count) {
                   _complect(_indexArray);   
                }
              
            }];
             Y += attrView.frame.size.height+10;
            
            [self addSubview:attrView];
        }
        self.contentSize = flexibleSize(CGSizeMake(frame.size.width,Y-10 ), YES);
    }
    return self;
}



@end
